package bishi.jingdong;

import java.util.*;

public class demo1 {
    static Map<Integer,Integer> hashRet;
    public static void main(String[] args) {

        hashRet = new HashMap<>();
        Scanner in = new Scanner(System.in);

        int pep = in.nextInt();
        int schools = in.nextInt();

        int[] schoolHash = new int[schools+1];
        for(int i = 1;i <= schools;i++) {
            schoolHash[i] = in.nextInt();
        }
        int[] schoolNowHash = new int[schools+1];

        List<List<Integer>> scores = new ArrayList<>();
        List<List<Integer>> goTo = new ArrayList<>();
        for(int j = 0;j < pep;j++) {
            List<Integer> newScore = new ArrayList<>();
            List<Integer> newGoTo = new ArrayList<>();
            int i = 0;
            for(;i < 5;i++) {
                newScore.add(in.nextInt());
            }

            for(;i < 5+schools;i++) {
                newGoTo.add(in.nextInt());
            }
            scores.add(newScore);
            goTo.add(newGoTo);
        }

        //排序
        sortAll(scores,goTo);


        int[] ret = new int[pep];
        int index = 0;
        int haveSchool = 0;
        for(int i = 0;i < scores.size() - 1;) {
            if(haveSchool > schools) {
                break;
            }
            //比较和下一个成绩是否相同
            if(check(scores,index)) {
                //比下个人成绩高
                //依次检查志愿学校满员没有
                choiceSchool(ret,index,goTo,schoolNowHash,schoolHash);
                ++index;
                haveSchool++;
                i++;
            }else {
                //成绩相同，依次比较科目
                if(checkScores(index,scores)) {
                    //第一个成绩高
                    choiceSchool(ret,index,goTo,schoolNowHash,schoolHash);
                    ++index;
                    choiceSchool(ret,index,goTo,schoolNowHash,schoolHash);
                    ++index;
                }else {
                    //第二个成绩高
                    choiceSchool(ret,index + 1,goTo,schoolNowHash,schoolHash);
                    choiceSchool(ret,index,goTo,schoolNowHash,schoolHash);
                    index += 2;
                }
                haveSchool = haveSchool + 2;
                i = i + 2;
            }
        }

        //更正映射
        int[] lastRet = new int[pep];
        for(int i = 0; i < lastRet.length;i++) {
            lastRet[hashRet.get(i)] = ret[i];
        }


        for(int i = 0;i < lastRet.length;i++) {
            if(lastRet[i]  == 0) {
                System.out.println(-1);
            }else {
                System.out.println(lastRet[i]);
            }
        }



    }

    static void sortAll(List<List<Integer>> scores,List<List<Integer>> goTo) {
        int[] sums = new int[scores.size()];
        Map<Integer,Integer> hash = new HashMap<>();

        Map<Integer,List<Integer>> hashListScore = new HashMap<>();
        Map<Integer,List<Integer>> hashListgoTo = new HashMap<>();
        //排序
        for(int i = 0;i < scores.size();i++) {
            int sum = 0;
            for(int j = 0;j < scores.get(i).size();j++) {
                sum += scores.get(i).get(j);
            }
            sums[i] = sum;
            hash.put(sum,i);
            hashListScore.put(i,scores.get(i));
            hashListgoTo.put(i,goTo.get(i));
        }

        Arrays.sort(sums);

        int left= 0;
        int right = sums.length-1;
        while(left < right) {
            int tem = sums[left];
            sums[left] = sums[right];
            sums[right] = tem;
            right--;
            left++;
        }

        for(int i = 0;i < scores.size();i++) {
            //交换 成绩
            scores.set(i,hashListScore.get(hash.get(sums[i])));
            //交换 志愿
            goTo.set(i,hashListgoTo.get(hash.get(sums[i])));


            //记录排序后的名称和租最初的映射
            hashRet.put(i,hash.get(sums[i]));
        }
    }

    static boolean checkScores(int index,List<List<Integer>> scores) {
        List<Integer> fir = scores.get(index);
        List<Integer> sec = scores.get(index + 1);

        for(int i = 0;i < fir.size();i++) {
            if(fir.get(i) > sec.get(i)) {
                return true;
            }else if(fir.get(i) < sec.get(i)) {
                return false;
            }
        }
        return true;
    }
    static void choiceSchool(int[] ret,int index,List<List<Integer>> goTo
            ,int[] schoolNowHash,int[] schoolHash) {
        List<Integer> onweSchool = goTo.get(index);
        for(int x : onweSchool) {
            if(schoolNowHash[x] < schoolHash[x]) {
                ret[index] = x;
                ++schoolNowHash[x];
                break;
            }
        }
    }
    static boolean check(List<List<Integer>> scores,int index) {
        List<Integer> fir = scores.get(index);
        List<Integer> sec = scores.get(index + 1);

        int firSum = 0;
        int secSum = 0;

        for(int x : fir) {
            firSum += x;
        }
        for(int x : sec) {
            secSum += x;
        }

        if(firSum>secSum) {
            return true;
        }else  {
            return  false;
        }

    }
}
